import type { ResponseData } from '@/utils/request';
import { request } from 'umi';
import type { QueryParams, ReservationOrderListItem, ReserveOrderDetail } from './data';

export async function getOrderList(params: QueryParams) {
  const { current, pageSize, ...param } = params;

  // TODO: 请求类型
  // const nes:QueryParamsReq = {
  const reqData: any = {
    ...param,
    page_size: pageSize,
    page: current,
  };

  console.log('reqData', reqData);

  const res: ResponseData<{ total: number; list: ReservationOrderListItem[] }> = await request(
    '/reservation/get_reserve_orders',
    {
      method: 'POST',
      data: reqData,
    },
  );

  if (res.code == 0) {
    return { success: true, total: res.data.total, data: res.data.list };
  }

  return { success: false, total: 0, data: [] };
}

export async function getOrderDetail(
  id: string,
): Promise<{ success: boolean; data?: ReserveOrderDetail; msg?: string }> {
  const res: ResponseData<ReserveOrderDetail> = await request(`/reservation/${id}`);
  console.log('res', res);

  if (res.code == 0) {
    return { success: true, data: res.data };
  }
  return { success: false, msg: res.message };
}
